//
//  BlackListViewController.m
//  QT
//
//  Created by 甘世清 on 2025/1/7.
//

#import "BlackListViewController.h"
#import "BlackListCollectionViewCell.h"
#import "PeopleDetailsViewController.h"
@interface BlackListViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@end

@implementation BlackListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.zx_navTitle = SQNSLocalString(@"黑名单");
}
- (void)SQ_viewWillAppear:(BOOL)animated{
    if (self.jsonArray.count<= 0) {
        [self SQ_Header];
    }
}
- (void)SQ_UIViewForSelfView{
    self.collectionView.backgroundColor = UIColor.whiteColor;
    [self.collectionView registerClass:[BlackListCollectionViewCell class] forCellWithReuseIdentifier:@"BlackListCollectionViewCell"];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.view addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.view);
        make.top.equalTo(self.zx_navBar.mas_bottom);
    }];
    [self SQ_collectViewAddRefresh];
}

- (void)SQ_Header{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:@"1" forKey:@"current"];
    [dic setObject:@"20" forKey:@"size"];
    [HttpTool post:@"blacklist/list" paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        self.page = 1;
        [self.collectionView.mj_header endRefreshing];
        NSDictionary * data = [[NSDictionary alloc]initWithDictionary:httpModel.data];
        NSArray * array = [UserModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"records"]];
        [self.jsonArray removeAllObjects];
        [self.jsonArray addObjectsFromArray:array];
        [self.collectionView reloadData];
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [self.collectionView.mj_header endRefreshing];
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
}
- (void)SQ_Foother{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:[NSString stringWithFormat:@"%d",self.page+1] forKey:@"current"];
    [dic setObject:@"20" forKey:@"size"];

    [HttpTool post:@"blacklist/list" paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        self.page ++;
        NSDictionary * data = [[NSDictionary alloc]initWithDictionary:httpModel.data];
        NSArray * array = [UserModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"records"]];
        [self.jsonArray addObjectsFromArray:array];
        [self.collectionView reloadData];
        [self.collectionView.mj_footer endRefreshing];
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [self.collectionView.mj_footer endRefreshing];
    }];
}

#pragma mark UICollectionViewDelegate,UICollectionViewDataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.jsonArray.count+10;
    
}

-(UICollectionViewCell *)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath{
    BlackListCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BlackListCollectionViewCell" forIndexPath:indexPath];
    cell.model = [UserModel share];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat w = SCREEN_WIDETH/2.f-10;
    return CGSizeMake(w, 320);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 8;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 0;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(0, 5, 0, 5);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    PeopleDetailsViewController * vc = [[PeopleDetailsViewController alloc]init];
    vc.userid = @"1";
    [self SQ_pushViewControllerFull:vc];
    
}


@end
